//
//  MainTabBar.swift
//  swift新浪微博
//
//  Created by sunchanggui on 15/7/28.
//  Copyright © 2015年 sunchanggui. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    override func layoutSubviews() {
        super.layoutSubviews()
        
        let count = 5
        let w = self.bounds.size.width / CGFloat(count)
        let h = self.bounds.size.height
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        var index = 0
        for v in subviews {
            if v is UIControl && !(v is UIButton) {
                v.frame = CGRectOffset(rect, w * CGFloat(index), 0)
                index += (index == 1 ? 2 : 1)
                //print("\(index)-----\(v)")
            }
        }
        
        self.composedButton.frame = rect
        self.composedButton.center = CGPoint(x: self.center.x, y: h * 0.5)
    }
    
    lazy var composedButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Selected)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Selected)
        
        self.addSubview(button)
        return button
    }()

}
